//
//  BugUploadVC.swift
//  ANOA
//
//  Created by 邱仙凯 on 2023/5/25.
//  Copyright © 2023 zwb. All rights reserved.
//

import UIKit
 
class BugUploadVC: GlobalFormVC,DateWidgetable,KSImageUtilDelegate {

    var itemTip:KSFormHItem = {
        let appe = KSFormHAppear()
            .tipStr("该功能会提交给开发者您最近30分钟内的操作日志，以便于开发者分析问题，您可以在操作异常30分钟内回来点击上报，超过30分钟的操作不会有任何记录\n您也可以留下回访微信号或邮箱，便于我们对问题进行回访")
            .contentHight(180)
            .roundType(.top)
        let v = KSFormHItem(title: "",appearance:appe,type:.tempTip )
        v.setLineHidden(true)
        return v
    }()
    var itemContact :KSFormHItem = {
        let appe = KSFormHAppear()
         let v = KSFormHItem(title: "回访联系方式",appearance:appe)
         return v
    }()
  var itemRemark :KSFormVItem = {
      let appe = KSFormVAppear()
          .contentHight(100)
      let v = KSFormVItem(title: "备注",appearance:appe,type:.tempTextView)
       return v
  }()
 
 var remark = ""
    var contact = ""
   var imageArray = [UIImage]()
  override func viewDidLoad() {
      super.viewDidLoad()
      self.title = "操作异常上报"
      
     configRow()
     
      
  }

   
  
  func configRow () {
      self.configView()
      self.configAction()
      self.configDataSource()

 
  }
  
  func configView() {
      
      
      bg.add(itemTip).add(itemContact).add(itemRemark)
         
      let appe = KSImageSelectAppear()
          .sectionTitle("异常截图")
      
      let viewFlag:ImgViewType =  .editable
      imageUtil = KSImageSelectUtil(frame: CGRect(x:0,y:itemRemark.frame.maxY,width:bg.ks_width ,height:singleImgHeight * 2),httpHeader: "",numberOfRow: 5,viewType:viewFlag,appear: appe)
      imageUtil?.ksDelegate = self
      bg.addv(view: imageUtil!)
      
 

    
 
      header.ks_height = bg.frame.maxY
      tableVw.tableHeaderView = header
      
      let footerv = FootRoundView()
       
              footerv.addSubV(subv: footSubmit)
               tableVw.tableFooterView = footerv
    
      
  }
  func configAction() {
      submitButton.button.addTouchUpInSideAction { _ in
          self.saveAction()
      }
      itemContact.textValueChangeClo = { str in
          self.contact = str
      }
      itemRemark.textValueChangeClo = { str in
          self.remark = str
      }
    
   }
  func configDataSource() {
    

  }
  
  func addImages(_ util: KSImageSelectUtil, imgs: [UIImage]) {
     
      for item in imgs {
       
          self.imageArray.append(item)
       }

  }
  
  func deleteImage(_ util: KSImageSelectUtil, index: Int) {
      alertUtil(self, title: "确定删除", operateS: [nameAction(name: "确定", action: { _ in
          
                   self.imageArray.remove(at: index)
                  self.imageUtil!.deleteLocalImg(tag: index)
           

       })])
  }

  
  // MARK: - 提交
  func saveAction() {
  
          KSToast("开始上传。。。")
          SKPSMTPMeService.shared.startUploadLog(contact:self.contact,remark: self.remark, imgs: self.imageArray )
          SKPSMTPMeService.shared.refreshClosure = {
              self.navigationController?.popViewController(animated: true)
          }
   
  }
  

}
